import { createStore } from 'redux'
//组件中的共享数据;
const cart = []
const checked = false
//设置reducer
function reducer(state = cart, action) {
  switch (action.type) {
    case '加入购物车':
      state.unshift(action.payload)
      return state
      break
    case '数量加':
      state[action.payload].num++
      return state
      break
    case '加1':
      state[action.payload].num++
      return state
      break
    case '减1':
      if (state[action.payload].num > 1) {
        state[action.payload].num--
      }
      return state
      break
    case '删除':
      state.splice(action.payload, 1)
      return state
      break
    case '全选':
      return state
      break
    default:
      return state
  }
}
//创建store
var store = createStore(reducer)
export default store
